home *** CD-ROM | disk | FTP | other *** search
Oberon Text | 1991-02-15 | 5.4 KB | 97 lines | [.Ob./.Ob2] |
- Syntax10.Scn.Fnt
- Syntax10i.Scn.Fnt
- EditKeys 1.0 cas 10-Aug-90 Keyboard Macros for Ed Editor
- You must compile EditKeys first before you can use them.
- EditKeys are not linked with the Ed Editor, but added
- using Oberon.Call (see below). If this call returns NIL, Ed just continues
- to work without them!
- Compiler.Compile EditKeys.Mod ~
- for programmers of macro extensions: Ed.Open KeyCmds.Mod
- * "Copy Out Tool" for using EditKeys.
- EditKeys.Definitions
- EditKeys.ReadFiles EditKeys.Text ~
- EditKeys.Reset
- EditKeys.GetKeyCode
- EditKeys.Definitions opens a viewer and lists all current macro definitions. A selection or a command parameter can be
- used to restrict the list to definitions with a certain prefix. EditKeys.ReadFiles takes a list of files and reads in macro
- definitions contained therein. If errors are detected, all definitions are deleted. Upon module load time, the standard
- macro definition file "EditKeys.Text" is read in. EditKeys.Reset deletes all current macro definitions. EditKeys.GetKeyCode
- helps to find out the codes of certain keys. Within a text supporting macro keys, entering the hot key causes expansion of the
- macro entered to the left. If no corresponding definition of a macro is found, a second try is made with the standard macro
- name "OTHERWISE".
- * Syntax of macro definition files for EditKeys.
- MacroFile = [HotKeyDef] {MacroDef}.
- HotKeyDef = "\" KeyName. -- sets the macro expansion hot key (default is \)
- MacroDef = MacroName "(" { MacroName | TextStretch | Command} ")".
- MacroName = KeyName | { <arbitrary graphic character except #, (, ), \, ^, and "> }.
- TextStretch = """ <arbitrary formatted text> """.
- KeyName = "#" <hex number>.
- (Comments and arbitrary white space are allowed between any two terminals. Comments may be nested.)
- * Built-in functions.
- Text stretches are pushed on a parameter stack when processed. Built-in functions may pop parameter(s)
- from that stack.
- ^0 pops a parameter and causes textual insertion.
- ^1 pops a parameter and inserts the corresponding ascii character.
- ^2 pops a parameter which must be a font name; presets the named font.
- ^4 pops a parameter and tries to call it as an Oberon command.
- ^5 keeps the font that would have been used w/o macro; presets this font.
- ^6 picks the font that would have been used w/o macro; forces whole macro to this font.
- ^7 presets the caret position.
- ^8 indents the next line according to the last line's indentation.
- (Parameters are pushed on a stack when processed. Built-in functions pop parameter(s) from that stack.)
- * Remarks.
- When reading in a macro that has been read in before, the new definition replaces the old one.
- Cyclic definitions can be constructed this way; a try to process such a definition is prevented.
- EditKeys and TBoxKeys are compatible in that both support macro files with the same syntax.
- The only difference is that EditKeys does not support changing the offset of characters (^3 in TBoxKeys).
- * Programmer's interface.
- Besides its command interface, EditKeys provides for interfacing to some text editor. Currently, EditKeys is
- integrated into the editors Ed and ET.
- PROCEDURE GetHandler;
- To be called via Oberon.Call, this procedure allows run-time binding of EditKeys to an editor. Thus the
- editor is usable even if the EditKeys module is not available. In order to bind EditKeys to some editor
- procede as follows:
- MODULE Editor;
- IMPORT
- Oberon;
- VAR
- macroHandler: Display.Handler;
- PROCEDURE* Handler(F: Display.Frame; VAR msg: Display.FrameMsg); (*editor specific handler*)
- BEGIN
- IF macroHandler # NIL THEN macroHandler(F, msg) END; (*must be first*)
- ...
- END Handler;
- PROCEDURE InstallMacros;
- CONST Magic = -42;
- VAR save: Oberon.ParList; res: INTEGER; name: ARRAY 32 OF CHAR;
- BEGIN save := Oberon.Par;
- NEW(Oberon.Par); NEW(Oberon.Par.frame); Oberon.Par.frame.X := 0; Oberon.Par.frame.Y := 0;
- Oberon.Par.pos := Magic;
- name := "EditKeys.GetHandler"; Oberon.Call(name, Oberon.Par, FALSE, res);
- IF res = 0 THEN macroHandler := Oberon.Par.frame.handle ELSE macroHandler := NIL END;
- Oberon.Par := save
- END InstallMacros;
- BEGIN InstallMacros
- END Editor;
- The EditKeys handler consumes some Oberon.InputMsg messages with id = Oberon.consume by setting id to -1.
- All other messages are either ignored or merely inspected. It is expected that the frame passed to the EditKeys
- handler is either a TextFrames.Frame or an extension thereof. A macro expansion leads to direct manipulation
- of the text attached to the frame (text inserts and deletions).
- The relevant section from Ed looks like:
- PROCEDURE GetMacroHandle(VAR Handle: Display.Handler);
- VAR cmd: ARRAY 32 OF CHAR; save, par: Oberon.ParList; res: INTEGER;
- BEGIN
- save := Oberon.Par;
- NEW(par); NEW(par.frame); par.frame.X := 0; par.frame.Y := 0; par.pos := -42; (* magic *)
- cmd := "EditKeys.GetHandler"; Oberon.Call(cmd, par, FALSE, res);
- IF res = 0 THEN Handle := Oberon.Par.frame.handle
- ELSE Handle := NIL; Modules.res := 0
- END;
- Oberon.Par := save
- END GetMacroHandle;
- PROCEDURE Handle*(F: Display.Frame; VAR msg: Display.FrameMsg);
- BEGIN
- IF MHandle # NIL THEN MHandle(F, msg) END; (* Handle Macro *)
- WITH F: TextFrames.Frame DO
- ...
-